#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 此结果与 iostat -x 1 不符
import psutil
import time

cur_disk_rec=psutil.disk_io_counters(perdisk=True)
sleep_time=2
for i in range(10):
    print i
    time.sleep(sleep_time)
    cur_disk_rec=psutil.disk_io_counters(perdisk=True)
    for disk in cur_disk_rec:
        delta_read_time = cur_disk_rec[disk].read_time - pre_disk_rec[disk].read_time
        delta_write_time = cur_disk_rec[disk].write_time - pre_disk_rec[disk].write_time
        delta_busy_time = delta_read_time + delta_write_time
        # delta_busy_time = cur_disk_rec[disk].busy_time - pre_disk_rec[disk].busy_time

        # delta_busy_time / (sleep_time * 1000) * 100
        busy_percent = float(delta_busy_time) / (sleep_time * 10)
        print "%s: busy_percent=%.2f" %(disk,busy_percent)
        pre_disk_rec=cur_disk_rec